package com.dudu.util;

import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by dudu on 16/8/26.
 */
public class DateUtil {

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    public static String dateToString(Date date) {
        if (null == date) {
            return null;
        } else {
            return sdf.format(date);
        }
    }

    public static Date stringToDate(String dateStr) throws ParseException{
        Date date = null;
        sdf.setLenient(false);
        if(StringUtils.isNotBlank(dateStr)) {
            date = sdf.parse(dateStr);
        }

        return date;
    }


}
